<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('巩固项目')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="data-form">
                <div class="select-list">
                    <ul>
                        <li>
                            <label style="width: 110px">搜索训练项目：</label>
                            <input type="text" name="trainingContent" placeholder="输入至少两个中文或数字"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <input id="programId" name="programId" type="hidden" th:value="*{programId}"/>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    var prefix = ctx + "education/schedule";
    $(function () {
        var options = {
            url: prefix + "/listReplaceTrainingProgram",
            rememberSelected: true,
            pagination: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            singleSelect: true,
            queryParams: queryParams,
            columns: [
                {
                    field: 'state',
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '',
                    visible: false

                },
                {
                    field: 'trainingContent',
                    title: '项目描述',
                    align: "center"
                }]
        };
        $.table.init(options);
    });



    function queryParams(params) {
        var programId = $("#programId").val();
        // var projectType = $("#projectType").val();
        // var scheduleTime = $("#scheduleTime").val();
        var search = $.table.queryParams(params);
        search.programId = programId;
        // search.projectType = projectType;
        // search.trainingProgramNumber =scheduleTime;
        return search;
    }


    function submitHandler() {
        var rows = $.table.selectFirstColumns();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }

        var selectId = $.table.selectColumns("id");
        // var data= $('#bootstrap-table').bootstrapTable('getData',true);
        // var selectData = [];
        // for(var i = 0;i<arrayIds.length;i++){
        //     for(var j=0;j<data.length;j++) {
        //         if(arrayIds[i] == data[j].id) {
        //             selectData[i] = data[j];
        //         }
        //     }
        // }
        var data={};
        data.newProgramId = selectId[0];
        data.oldChildTrainingId = $("#programId").val();
        $.ajax({
            cache: true,
            type: "POST",
            url: prefix + "/saveReplaceProgram",
            data: data,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                if (data.code == 0) {
                    // $.modal.close();
                    // parent.submitSelect();
                    parent.refresh();
                    $.modal.close();
                } else {
                    $.modal.alertError(data.msg);
                }
            }
        });

    }

</script>
</body>

</html>